package cn.hy.prac.controller.orderpay;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mobile.device.site.SitePreference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.sun.org.apache.xpath.internal.operations.Mod;

import cn.hy.prac.service.orderpay.OrderPayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 单独的支付工程，供其他工程调用
 * @author Administrator
 *
 */
//swagger-spring项目实现了与SpingMVC框架的无缝集成功能，方便生成spring restful风格的接口文档
@Api(tags="支付相关接口") 
@Controller
@RequestMapping("/bpay")
public class OrderPayController {

	@Autowired
	private OrderPayService orderPayService;
	
	/**
	 * 发起支付
	 * @author haoyi 
	 * @return
	 */
	@ApiOperation(value="发起支付", httpMethod="GET", response=String.class, notes="跳转到支付页面")
	@RequestMapping(value="/send/{ordernum}/{type}", method=RequestMethod.GET)
	public String send(
			@ApiParam(value="以moko+20位数字组成", required=true)
			@PathVariable("ordernum") String ordernum, 
			@ApiParam(value="{1:微信, 2:支付宝}", required=true)
			@PathVariable("type") int type, SitePreference sitePreference){
		String url = orderPayService.sendPay(ordernum, type, sitePreference.isMobile());
		return "redirect:"+ (url==null ? "/" : url);
	}
	
	/**
	 * 支付回调
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/payReturn", method=RequestMethod.GET)
	public String payReturn(Model model){
		
		//暂未做处理，默认付款成功
		
		return "/success.jsp";
	}
}
